Page({
  data: {
    block: false,
    restaurant: false,
    check: true,
    orderArr: [],
    orderData: []
  },
  calling: function () {
    wx.makePhoneCall({
      phoneNumber: '18316588252',
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },
  onLoad: function (options) {
    var that = this

    wx.getStorage({
      key: "arrSelected",
      success(res) {
        that.setData({
          orderData: res.data
        })
        // that.orderList()
      }
    })

  },
  submitOrder: function () {
    var that = this
    let total = 0
    that.data.orderData.forEach(ele => {
      total += ele.price * ele.selectCount
    })
    wx.request({
      url: 'https://calamar.top:8081/order/placeOrder', //仅为示例，并非真实的口址
      method: 'post',
      data: {
        shopId: '1',
        userId: '18721260590',
        total: total * 100,
        priceItem: that.data.orderData.map(ele => {
          return {
            productId: ele.productId,
            num: ele.selectCount,
            price: ele.price * 100,
            name: ele.name,
            shoppingCartId: ele.id,
          }
        })
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        if(res.data.code !=="000000"){
          wx.showModal({
            title: '提示', content: res.data.description
          })
        }else{
          wx.showToast({
            title: '新增成功',
            icon: 'success',
            duration: 1000,
            mask: true,
            success: function() {
              setTimeout(function() {
                //要延时执行的代码
                wx.navigateTo({
                  url: '../index/index',
                })
              }, 1000) //延迟时间
            },
          });
        }







      }
    })
  },

  Block: function () {
    this.setData({
      block: true
    })
  },
  takeOut: function () {
    this.setData({
      restaurant: false
    })
  },
  Cancel: function () {
    this.setData({
      block: false,
      check: true,
      restaurant: false
    })
  },
  Ok: function () {
    var that = this;
    this.setData({
      block: false,
    })
    wx.scanCode({
      onlyFromCamera: true,
      success: (res) => {
        console.log(res);
        that.setData({
          restaurant: true
        })
      },
      fail: (res) => {
        that.setData({
          restaurant: false,
          check: true
        });
      }
    })
  },
  toMyPackage: function () {
    wx.navigateTo({
      url: '../myPackage/myPackage',
    })
  },
  toMyAddress: function () {
    wx.navigateTo({
      url: '../address/address',
    })
  },
})